package com.ebt.m.proposal_v2.ui.view;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.BaseListView;
import com.ebt.m.commons.buscomponent.listview.BasePresenter;
import com.ebt.m.proposal_v2.dao.request.ParamGetRisks;
import com.ebt.m.proposal_v2.mvp.presenter.MainProductSearchPresenter;
import com.ebt.m.utils.RecyclerViewDivider;
import com.ebt.m.commons.buscomponent.listview.ISectionFactory;

/**
 * 按照关键字搜索
 */
public class SpecProductSearchListView extends BaseListView<MainProductSearchPresenter> {

    public ParamGetRisks paramGetRisks;

    public SpecProductSearchListView(Context context) {
        this(context, null, 0);
    }

    public SpecProductSearchListView(Context context, ParamGetRisks param) {
        super(context);
        this.paramGetRisks = param;
        initView(context);
    }

    public SpecProductSearchListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public SpecProductSearchListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        mRecyclerView.addItemDecoration(new RecyclerViewDivider(context, LinearLayoutManager.HORIZONTAL, (int) getResources().getDimension(R.dimen.common_divider_dimen), getResources().getColor(R.color.common_divider_color)));
    }


    @Override
    protected ISectionFactory createViewFactory() {
        return viewType -> new MainProductItemView(getContext(), paramGetRisks);
    }

    @Override
    protected MainProductSearchPresenter createPresenter() {
        return new MainProductSearchPresenter(getContext(), this);
    }

    @Override
    public void update(Object... args) {
        super.update(args);
        mPresenter.loadNew(args);
    }

    @Override
    public void loadNext() {
        mPresenter.loadNext();
    }

    @Override
    protected View configEmptyView() {
        View emptyContent = LayoutInflater.from(getContext()).inflate(R.layout.layout_product_search_empty, null);
        ImageView imageView = (ImageView) emptyContent.findViewById(R.id.img_empty);
        TextView textView = (TextView) emptyContent.findViewById(R.id.mession_empty);
        imageView.setBackgroundResource(R.drawable.ic_empty_product);
        textView.setText(R.string.product_search_null1);
        return emptyContent;
    }

    @Override
    protected boolean createFootView() {
        return true;
    }
}
